package com.fmjava.controller;

import com.fmjava.ServiceImpl.NewsServiceImpl;
import com.fmjava.domain.PageBean;
import com.fmjava.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/NoticeListServlet")
public class NoticeListServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        request.setAttribute("type", request.getParameter("type"));
        request.setAttribute("id", 3);//防指js出错

        //取数据
        NewsService newService = new NewsServiceImpl();

        //处理分页操作
        String currentPage = request.getParameter("currentPage");//获取当前页数
        String pageSize = request.getParameter("pageSize");
        if (currentPage == null || "".equals(currentPage)) {
            currentPage = "1";//默认显示第一页
        }
        if (pageSize == null || "".equals(pageSize)) {
            pageSize = "3";//默认显示前3行数据
        }
        // List<News> newsList=newService.getNewsWithCategory(cacheKey);
        PageBean noticeList = newService.getPageBean(currentPage, pageSize, request.getParameter("type"));
        request.setAttribute("noticeList", noticeList);
        request.getRequestDispatcher("/notice_list.jsp").forward(request, response);
    }
}
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        doGet(request,response);
//    }
//
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
////        String type = request.getParameter("type");
////        request.setAttribute("type",type);
////        System.out.println(type);
////        request.setCharacterEncoding("utf-8");
////
////        //取数据
////        NewsService newService=new NewsServiceImpl();
////
////        //处理分页操作
////        String currentPage=request.getParameter("currentPage");//获取当前页数
////        String pageSize = request.getParameter("pageSize");
////        if (currentPage == null||"".equals(currentPage)) {
////            currentPage="1";//默认显示第一页
////        }
////        if (pageSize == null ||"".equals(pageSize) ){
////            pageSize="5";//默认显示数据行数
////        }
////
////        // List<News> newsList=newService.getNewsWithCategory(cacheKey);
////        PageBean noticeList = newService.getPageBean(currentPage, pageSize,request.getParameter("type"));
////        request.setAttribute("noticeList",noticeList);
////        System.out.println(noticeList);
////        request.getRequestDispatcher("/notice_list.jsp").forward(request, response);
//    }
//}
